 package es.ats.codington.festival.services;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;

import es.ats.codington.festival.daos.EventDAOImp;
import es.ats.codington.festival.domain.Event;
import es.ats.codington.festival.interfaces.services.IEventService;
import es.ats.codington.festival.utils.FERSDataConnection;

public class EventDAOService implements IEventService{

	int nRows = 0;
	private Connection con;
	EventDAOImp eventDAO = new EventDAOImp();

	public EventDAOService() {
		
	}
	/**
	 *  GETTER methods for EventDAOService class 
	 * @return
	 */
	public Event getEventByIdService(int eventId, String usTickets){
		Event event = new Event();
		try{
			con = FERSDataConnection.getConnection();
			event = eventDAO.getEventById(eventId, usTickets, con);
			con.close();
		}catch (SQLException e){
			System.out.println(e.getMessage());
		}
		return event;
	}
	/**
	 *  GETTER methods for EventDAOService class 
	 * @return
	 */
	public Event getEventByIdService(int eventId){
		Event event = new Event();
		try{
			con = FERSDataConnection.getConnection();
			event = eventDAO.getEventById(eventId, con);
			con.close();
		}catch (SQLException e){
			System.out.println(e.getMessage());
		}
		return event;
	}
	
	/**
	 *  GETTER methods for EventDAOService class 
	 * @return
	 */
	public ArrayList<Event> getEventListService(){
		ArrayList<Event> listEvents = new ArrayList<Event>();
		try{
			con = FERSDataConnection.getConnection();
			listEvents = eventDAO.getEventList(con);
			con.close();
		}catch (SQLException e){
			System.out.println(e.getMessage());
		}
		return listEvents;
	}
	/**
	 *  SETTER methods for EventDAOService class 
	 * @return
	 */
	public int insertEventService(Event event){
		try{
			con = FERSDataConnection.getConnection();
			nRows = eventDAO.insertEvent(event, con);
			con.close();
		}catch (SQLException e){
			System.out.println(e.getMessage());
		}
		return nRows;
	}
	/**
	 *  SETTER methods for EventDAOService class 
	 * @return
	 */
	public int updateEventService(Event uEvent){
		try{
			con = FERSDataConnection.getConnection();
			nRows = eventDAO.updateEvent(uEvent, con);
			con.close();
		}catch (SQLException e){
			System.out.println(e.getMessage());
		}
		return nRows;
	}
	/**
	 *  SETTER methods for EventDAOService class 
	 * @return
	 */
	public int deleteEventService(int eventId){
		try{
			con = FERSDataConnection.getConnection();
			nRows = eventDAO.deleteEvent(eventId, con);
			con.close();
		}catch (SQLException e){
			System.out.println(e.getMessage());
		}
		return nRows;
	}
}
